function getDefaultExportFromCjs(e) {
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default")
    ? e.default
    : e;
}
var md5$1 = {
    exports: {},
  },
  crypt = {
    exports: {},
  },
  base64map,
  crypt$1;
(base64map =
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),
  (crypt$1 = {
    rotl: function (e, t) {
      return (e << t) | (e >>> (32 - t));
    },
    rotr: function (e, t) {
      return (e << (32 - t)) | (e >>> t);
    },
    endian: function (e) {
      if (e.constructor == Number)
        return (
          (16711935 & crypt$1.rotl(e, 8)) | (4278255360 & crypt$1.rotl(e, 24))
        );
      for (var t = 0; t < e.length; t++) e[t] = crypt$1.endian(e[t]);
      return e;
    },
    randomBytes: function (e) {
      for (var t = []; e > 0; e--) t.push(Math.floor(256 * Math.random()));
      return t;
    },
    bytesToWords: function (e) {
      for (var t = [], r = 0, n = 0; r < e.length; r++, n += 8)
        t[n >>> 5] |= e[r] << (24 - (n % 32));
      return t;
    },
    wordsToBytes: function (e) {
      for (var t = [], r = 0; r < 32 * e.length; r += 8)
        t.push((e[r >>> 5] >>> (24 - (r % 32))) & 255);
      return t;
    },
    bytesToHex: function (e) {
      for (var t = [], r = 0; r < e.length; r++)
        t.push((e[r] >>> 4).toString(16)), t.push((15 & e[r]).toString(16));
      return t.join("");
    },
    hexToBytes: function (e) {
      for (var t = [], r = 0; r < e.length; r += 2)
        t.push(parseInt(e.substr(r, 2), 16));
      return t;
    },
    bytesToBase64: function (e) {
      for (var t = [], r = 0; r < e.length; r += 3)
        for (
          var n = (e[r] << 16) | (e[r + 1] << 8) | e[r + 2], i = 0;
          i < 4;
          i++
        )
          8 * r + 6 * i <= 8 * e.length
            ? t.push(base64map.charAt((n >>> (6 * (3 - i))) & 63))
            : t.push("=");
      return t.join("");
    },
    base64ToBytes: function (e) {
      e = e.replace(/[^A-Z0-9+\/]/gi, "");
      for (var t = [], r = 0, n = 0; r < e.length; n = ++r % 4)
        0 != n &&
          t.push(
            ((base64map.indexOf(e.charAt(r - 1)) &
              (Math.pow(2, -2 * n + 8) - 1)) <<
              (2 * n)) |
              (base64map.indexOf(e.charAt(r)) >>> (6 - 2 * n))
          );
      return t;
    },
  }),
  (crypt.exports = crypt$1);
var cryptExports = crypt.exports,
  charenc = {
    utf8: {
      stringToBytes: function (e) {
        return charenc.bin.stringToBytes(unescape(encodeURIComponent(e)));
      },
      bytesToString: function (e) {
        return decodeURIComponent(escape(charenc.bin.bytesToString(e)));
      },
    },
    bin: {
      stringToBytes: function (e) {
        for (var t = [], r = 0; r < e.length; r++)
          t.push(255 & e.charCodeAt(r));
        return t;
      },
      bytesToString: function (e) {
        for (var t = [], r = 0; r < e.length; r++)
          t.push(String.fromCharCode(e[r]));
        return t.join("");
      },
    },
  },
  charenc_1 = charenc,
  isBuffer_1 = function (e) {
    return null != e && (isBuffer(e) || isSlowBuffer(e) || !!e._isBuffer);
  },
  crypt2,
  utf8,
  isBuffer2,
  bin,
  md52;
function isBuffer(e) {
  return (
    !!e.constructor &&
    "function" == typeof e.constructor.isBuffer &&
    e.constructor.isBuffer(e)
  );
}
function isSlowBuffer(e) {
  return (
    "function" == typeof e.readFloatLE &&
    "function" == typeof e.slice &&
    isBuffer(e.slice(0, 0))
  );
}
(crypt2 = cryptExports),
  (utf8 = charenc_1.utf8),
  (isBuffer2 = isBuffer_1),
  (bin = charenc_1.bin),
  (md52 = function e(t, r) {
    t.constructor == String
      ? (t =
          r && "binary" === r.encoding
            ? bin.stringToBytes(t)
            : utf8.stringToBytes(t))
      : isBuffer2(t)
      ? (t = Array.prototype.slice.call(t, 0))
      : Array.isArray(t) || t.constructor === Uint8Array || (t = t.toString());
    for (
      var n = crypt2.bytesToWords(t),
        i = 8 * t.length,
        o = 1732584193,
        a = -271733879,
        s = -1732584194,
        l = 271733878,
        c = 0;
      c < n.length;
      c++
    )
      n[c] =
        (16711935 & ((n[c] << 8) | (n[c] >>> 24))) |
        (4278255360 & ((n[c] << 24) | (n[c] >>> 8)));
    (n[i >>> 5] |= 128 << i % 32), (n[14 + (((i + 64) >>> 9) << 4)] = i);
    var u = e._ff,
      d = e._gg,
      p = e._hh,
      h = e._ii;
    for (c = 0; c < n.length; c += 16) {
      var f = o,
        m = a,
        v = s,
        g = l;
      (o = u(o, a, s, l, n[c + 0], 7, -680876936)),
        (l = u(l, o, a, s, n[c + 1], 12, -389564586)),
        (s = u(s, l, o, a, n[c + 2], 17, 606105819)),
        (a = u(a, s, l, o, n[c + 3], 22, -1044525330)),
        (o = u(o, a, s, l, n[c + 4], 7, -176418897)),
        (l = u(l, o, a, s, n[c + 5], 12, 1200080426)),
        (s = u(s, l, o, a, n[c + 6], 17, -1473231341)),
        (a = u(a, s, l, o, n[c + 7], 22, -45705983)),
        (o = u(o, a, s, l, n[c + 8], 7, 1770035416)),
        (l = u(l, o, a, s, n[c + 9], 12, -1958414417)),
        (s = u(s, l, o, a, n[c + 10], 17, -42063)),
        (a = u(a, s, l, o, n[c + 11], 22, -1990404162)),
        (o = u(o, a, s, l, n[c + 12], 7, 1804603682)),
        (l = u(l, o, a, s, n[c + 13], 12, -40341101)),
        (s = u(s, l, o, a, n[c + 14], 17, -1502002290)),
        (o = d(
          o,
          (a = u(a, s, l, o, n[c + 15], 22, 1236535329)),
          s,
          l,
          n[c + 1],
          5,
          -165796510
        )),
        (l = d(l, o, a, s, n[c + 6], 9, -1069501632)),
        (s = d(s, l, o, a, n[c + 11], 14, 643717713)),
        (a = d(a, s, l, o, n[c + 0], 20, -373897302)),
        (o = d(o, a, s, l, n[c + 5], 5, -701558691)),
        (l = d(l, o, a, s, n[c + 10], 9, 38016083)),
        (s = d(s, l, o, a, n[c + 15], 14, -660478335)),
        (a = d(a, s, l, o, n[c + 4], 20, -405537848)),
        (o = d(o, a, s, l, n[c + 9], 5, 568446438)),
        (l = d(l, o, a, s, n[c + 14], 9, -1019803690)),
        (s = d(s, l, o, a, n[c + 3], 14, -187363961)),
        (a = d(a, s, l, o, n[c + 8], 20, 1163531501)),
        (o = d(o, a, s, l, n[c + 13], 5, -1444681467)),
        (l = d(l, o, a, s, n[c + 2], 9, -51403784)),
        (s = d(s, l, o, a, n[c + 7], 14, 1735328473)),
        (o = p(
          o,
          (a = d(a, s, l, o, n[c + 12], 20, -1926607734)),
          s,
          l,
          n[c + 5],
          4,
          -378558
        )),
        (l = p(l, o, a, s, n[c + 8], 11, -2022574463)),
        (s = p(s, l, o, a, n[c + 11], 16, 1839030562)),
        (a = p(a, s, l, o, n[c + 14], 23, -35309556)),
        (o = p(o, a, s, l, n[c + 1], 4, -1530992060)),
        (l = p(l, o, a, s, n[c + 4], 11, 1272893353)),
        (s = p(s, l, o, a, n[c + 7], 16, -155497632)),
        (a = p(a, s, l, o, n[c + 10], 23, -1094730640)),
        (o = p(o, a, s, l, n[c + 13], 4, 681279174)),
        (l = p(l, o, a, s, n[c + 0], 11, -358537222)),
        (s = p(s, l, o, a, n[c + 3], 16, -722521979)),
        (a = p(a, s, l, o, n[c + 6], 23, 76029189)),
        (o = p(o, a, s, l, n[c + 9], 4, -640364487)),
        (l = p(l, o, a, s, n[c + 12], 11, -421815835)),
        (s = p(s, l, o, a, n[c + 15], 16, 530742520)),
        (o = h(
          o,
          (a = p(a, s, l, o, n[c + 2], 23, -995338651)),
          s,
          l,
          n[c + 0],
          6,
          -198630844
        )),
        (l = h(l, o, a, s, n[c + 7], 10, 1126891415)),
        (s = h(s, l, o, a, n[c + 14], 15, -1416354905)),
        (a = h(a, s, l, o, n[c + 5], 21, -57434055)),
        (o = h(o, a, s, l, n[c + 12], 6, 1700485571)),
        (l = h(l, o, a, s, n[c + 3], 10, -1894986606)),
        (s = h(s, l, o, a, n[c + 10], 15, -1051523)),
        (a = h(a, s, l, o, n[c + 1], 21, -2054922799)),
        (o = h(o, a, s, l, n[c + 8], 6, 1873313359)),
        (l = h(l, o, a, s, n[c + 15], 10, -30611744)),
        (s = h(s, l, o, a, n[c + 6], 15, -1560198380)),
        (a = h(a, s, l, o, n[c + 13], 21, 1309151649)),
        (o = h(o, a, s, l, n[c + 4], 6, -145523070)),
        (l = h(l, o, a, s, n[c + 11], 10, -1120210379)),
        (s = h(s, l, o, a, n[c + 2], 15, 718787259)),
        (a = h(a, s, l, o, n[c + 9], 21, -343485551)),
        (o = (o + f) >>> 0),
        (a = (a + m) >>> 0),
        (s = (s + v) >>> 0),
        (l = (l + g) >>> 0);
    }
    return crypt2.endian([o, a, s, l]);
  }),
  (md52._ff = function (e, t, r, n, i, o, a) {
    var s = e + ((t & r) | (~t & n)) + (i >>> 0) + a;
    return ((s << o) | (s >>> (32 - o))) + t;
  }),
  (md52._gg = function (e, t, r, n, i, o, a) {
    var s = e + ((t & n) | (r & ~n)) + (i >>> 0) + a;
    return ((s << o) | (s >>> (32 - o))) + t;
  }),
  (md52._hh = function (e, t, r, n, i, o, a) {
    var s = e + (t ^ r ^ n) + (i >>> 0) + a;
    return ((s << o) | (s >>> (32 - o))) + t;
  }),
  (md52._ii = function (e, t, r, n, i, o, a) {
    var s = e + (r ^ (t | ~n)) + (i >>> 0) + a;
    return ((s << o) | (s >>> (32 - o))) + t;
  }),
  (md52._blocksize = 16),
  (md52._digestsize = 16),
  (md5$1.exports = function (e, t) {
    if (null == e) throw new Error("Illegal argument " + e);
    var r = crypt2.wordsToBytes(md52(e, t));
    return t && t.asBytes
      ? r
      : t && t.asString
      ? bin.bytesToString(r)
      : crypt2.bytesToHex(r);
  });
var md5Exports = md5$1.exports,
  md5 = getDefaultExportFromCjs(md5Exports),
  formatString$1 = function (e) {
    for (var t = "", r = 0; r < e.length; r++)
      t += String.fromCharCode(e.charCodeAt(r) - 1);
    return t;
  };

function formatImgByLocalParams(e, t) {
  t || (t = {});
  var r = getImgFormatConfig(t),
    n = r.imgKey,
    i = r.subKey;
  console.log("r", r);
  if (n && i) {
    for (
      var o = getPictureHashKey(n + i),
        a = Math.round(Date.now() / 1e3),
        s = Object.assign({}, e, {
          wts: a,
        }),
        l = Object.keys(s).sort(),
        c = [],
        u = /[!'()*]/g,
        d = 0;
      d < l.length;
      d++
    ) {
      var p = l[d],
        h = s[p];
      h && "string" == typeof h && (h = h.replace(u, "")),
        null != h &&
          c.push(
            "".concat(encodeURIComponent(p), "=").concat(encodeURIComponent(h))
          );
    }
    var f = c.join("&");

    return {
      w_rid: md5(f + o),
      wts: a.toString(),
    };
  }
  return null;
}
const LOCAL_STORAGE_KEY$1 = "wbi_img_urls";

function getLocal(e) {
  try {
    return localStorage.getItem(e);
  } catch (e2) {
    return null;
  }
}

function getKeyFromURL(e) {
  return e.substring(e.lastIndexOf("/") + 1, e.length).split(".")[0];
}
function getImgFormatConfig(e) {
  console.log(e);
  var t;
  if (e.useAssignKey)
    return {
      imgKey: e.wbiImgKey,
      subKey: e.wbiSubKey,
    };
  var r = [
    "https://i0.hdslb.com/bfs/wbi/7cd084941338484aae1ad9425b84077c.png",

    "https://i0.hdslb.com/bfs/wbi/4932caff0ff746eab6f01bf08b70ac45.png",
  ];
  (n = r[0]), (i = r[1]);
  console.log(r);
  return {
    imgKey: n ? getKeyFromURL(n) : e.wbiImgKey,
    subKey: i ? getKeyFromURL(i) : e.wbiSubKey,
  };
}

function getPictureHashKey(e) {
  var t = [];
  return (
    [
      46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5,
      49, 33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55,
      40, 61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57,
      62, 11, 36, 20, 34, 44, 52,
    ].forEach(function (r) {
      e.charAt(r) && t.push(e.charAt(r));
    }),
    t.join("").slice(0, 32)
  );
}

const e = {
  web_location: "333.337",
};

const t = {
  wbiImgKey: "c458435a75b1419ca98ab6d88b4c60d4",
  wbiSubKey: "446140f6859f439e9dd83f7ef858d1cd",
};
w_rid = formatImgByLocalParams(e, t)["w_rid"];
wts = formatImgByLocalParams(e, t)["w_rid"];

const params = {
  __refresh__: "true",
  _extra: "",
  context: "",
  page: "1",
  page_size: "42",
  order: "",
  pubtime_begin_s: "0",
  pubtime_end_s: "0",
  duration: "",
  from_source: "",
  from_spmid: "333.337",
  platform: "pc",
  highlight: "1",
  single_column: "0",
  keyword: "快客", // Your search term
  qv_id: "YEHryvroAMDOFuyFsYNGKI4OhwAjmOTR",
  ad_resource: "5646",
  source_tag: "3",
  page_exp: "0",
  web_location: "1430654",
  wts: wts, // Current timestamp
  w_rid: "d50effed793261a80d4e693c3445c4d7",
};

// https://api.bilibili.com/x/web-interface/wbi/search/all/v2?__refresh__=true&_extra=&context=&page=1&page_size=42&order=&pubtime_begin_s=0&pubtime_end_s=0&duration=&from_source=&from_spmid=333.337&platform=pc&highlight=1&single_column=0&keyword=%E5%BF%AB%E5%AE%A2&qv_id=YEHryvroAMDOFuyFsYNGKI4OhwAjmOTR&ad_resource=5646&source_tag=3&page_exp=0&web_location=1430654&w_rid=d50effed793261a80d4e693c3445c4d7&wts=1746778328
const url = new URL(
  "https://api.bilibili.com/x/web-interface/wbi/search/all/v2"
);
// 将参数添加到URL的查询字符串中
Object.keys(params).forEach((key) => {
  if (params[key] !== "") {
    // 只添加非空参数
    url.searchParams.append(key, params[key]);
  }
});

fetch(url.toString(), {
  headers: {
    Referer: "https://www.bilibili.com/",
    "User-Agent":
      "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
    cookie:
      "buvid3=31774EA0-9553-6988-C446-B18A487A7FEF33095infoc; b_nut=1720673433; _uuid=7261E810A-C10B5-3D99-91110-91796EDAC69931325infoc; buvid4=2B69D6FE-2E4F-8FFE-FC3C-BD1CE99B8C2033710-024071104-HLeDl92X2OPzAShF26ElJw%3D%3D; DedeUserID=1493259707; DedeUserID__ckMd5=c5d05f93da6508f5; rpdid=|(~uuJJJ~Y)0J'u~k|Y~JlJ~; buvid_fp_plain=undefined; iflogin_when_web_push=1; header_theme_version=CLOSE; is-2022-channel=1; CURRENT_BLACKGAP=0; enable_web_push=DISABLE; enable_feed_channel=ENABLE; hit-dyn-v2=1; LIVE_BUVID=AUTO8917426391753315; opus-goback=1; CURRENT_QUALITY=80; BILI-MALL-MERCHANT-IS-COMPUTER=false; BILI-MERCHANT-SHOW-BLACK-MENU=1; BILI-MALL-MERCHANT-MAIN-ACCOUNT=true; fingerprint=cd6880556d85a52cfc63b90bf40666f3; SESSDATA=27addb53%2C1762238536%2C9755e%2A51CjD55UrXcrjDBPcQDI85saRJVwYPAQ2OOLBTXtYI_P39PA9OuqD92DX0RO-gUkt-9P4SVmY5aG9XdjBfMWxQa0pKODdLUVNIVkRINlQwMDRWX3B2VlNjdXh5Wkk3VEtVR29YMTFFREhzS1F6X1ptUk0zdjQxSlM0U3FkdzJCSmdrRng1T1BncXd3IIEC; bili_jct=af33c1d1773a415049ae526b3c3c9e52; go-old-space=-1; home_feed_column=5; buvid_fp=cd6880556d85a52cfc63b90bf40666f3; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDY5Njg0MjgsImlhdCI6MTc0NjcwOTE2OCwicGx0IjotMX0.Rmvk6D1Kaw8pTzwbN4MBgf4h_v6rPZULJnC9Nw0k31M; bili_ticket_expires=1746968368; bp_t_offset_1493259707=1064606772158791680; PVID=3; go-back-dyn=0; bsource=search_bing; browser_resolution=1912-928; sid=50ju9cor;",
  },
})
  .then((response) => response.text()) // First get as text to debug
  .then((text) => {
    try {
      return JSON.parse(text)["data"]["result"];
    } catch (e) {
      throw e;
    }
  })
  .then((data) => console.log(data))
  .catch((error) => console.error("Error:", error));
